﻿using System;

namespace MicroMq.Core
{
    [AttributeUsage(AttributeTargets.Method)]
    public class ListenAttribute : Attribute
    {
        /// <summary>
        /// 工作模式
        /// </summary>
        /// <param name="topic">主题</param>
        public ListenAttribute(string topic) : this(topic, "default")
        {

        }

        /// <summary>
        /// 可选模式
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="isPublish">是否发布订阅模式</param>
        public ListenAttribute(string topic, bool isPublish) : this(topic, "default")
        {
            if (!isPublish)
            {
                GroupId = Guid.NewGuid().ToString("N");
            }
        }

        /// <summary>
        /// 自定义组
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="groupId"></param>
        public ListenAttribute(string topic, string groupId)
        {
            Topic = topic;
            GroupId = groupId;
        }

        public string Topic { get; }
        public string GroupId { get; }
         
    }
}
